# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
inherit eutils rpm linux-info

MY_PV="3.13-4"
MY_P="${PN}-${MY_PV}"

DESCRIPTION="HighPoint RocketRaid configuration tool server."
HOMEPAGE="http://www.highpoint-tech.com"

SRC_URI="http://www.highpoint-tech.com/BIOS_Driver/HRM/Linux/CLI-Linux-2.3-3-1214.tgz"

LICENSE=""

SLOT="0"

KEYWORDS="~amd64 ~x86"

IUSE="kernel_linux"

RESTRICT="strip mirror"

DEPEND="dev-libs/openssl
	!sys-block/hptsvr-https"

RDEPEND="${DEPEND}"

pkg_setup() {
	if use kernel_linux ; then
		CONFIG_CHECK="SCSI_PROC_FS"
		linux-info_pkg_setup
	fi
}

src_unpack() {
	unpack ${A}
	cd "${WORKDIR}"

	einfo "Removing unnessary files form WORKDIR."
	rm "${WORKDIR}"/hptraidconf-*.rpm
	rm "${WORKDIR}"/*.pdf

	if use amd64; then
		einfo "Removing i586 rpm from WORKDIR."
		rm "${WORKDIR}/${MY_P}.i586.rpm"
		einfo "Unpacking ${MY_P}.x86_64.rpm"
		rpm_unpack "${WORKDIR}/${MY_P}.x86_64.rpm"
	elif use x86; then
		einfo "Removing x86_64 rpm from WORKDIR."
		rm "${WORKDIR}/${MY_P}.x86_64.rpm"
		einfo "Unpacking ${MY_P}.i586.rpm"
		rpm_unpack "${WORKDIR}/${MY_P}.i586.rpm"
	fi
}

src_install() {
	dobin "${WORKDIR}/usr/bin/hptsvr"
	insinto /usr/bin
	doins "${WORKDIR}/usr/bin/smart.def"
	cp -R "${WORKDIR}/usr/share" "${D}/usr/" || die "Install failed!"
	dodir /etc
	echo "hptmv6" > "${D}/etc/hptcfg"
	newinitd "${FILESDIR}/${P}-initd" hptsvr
}

pkg_postinst() {
	einfo "You need to edit /etc/hptcfg to use the correct driver."
	einfo "Otherwise hptmv6 is the default."
	einfo "Also, you need to have the hptsvr service start at boot time."
	einfo "     rc-update add hptsvr boot"
}
